
import MeasureLength from './plotShapes/MeasureLength' //线
import DrawCurve from './plotShapes/DrawCurve' //曲线
import DrawPolygon from './plotShapes/DrawPolygon' //面
//this._MeasureLength = new MeasureLength(option)
// this._MeasureLength.startCreate(option)//绘制
//// this._MeasureLength.getData()
//this._MeasureLength.loadPolyline(data)
//this._MeasureLength.destroy()
//this._MeasureLength.clear()
class plotsUnit {
  constructor(arg) {
    this.viewer = arg.viewer
    this.Cesium = arg.Cesium
    var option = arg
    this._MeasureLength = new MeasureLength(option)
    this._DrawCurve = new DrawCurve(option)
    this._DrawPolygon = new DrawPolygon(option)
  }

  //鼠标绘制
  DrawCreate(option) {
    this.destroy()
    switch (option.type) {
      case '线':
        this._MeasureLength.startCreate(option)
        break
      case '曲线':
        this._DrawCurve.startCreate(option)
        break
      case '多边形':
        this._DrawPolygon.startCreate(option)
        break
      default:
        break
    }

  }

  //获取绘制数据
  DrawGet(type) {
    var positions = null
    switch (type) {
      case '线':
        positions = this._MeasureLength.getData()
        break
      case '曲线':
        positions = this._DrawCurve.getData()
        break
      case '多边形':
        positions = this._DrawPolygon.getData()
        break
      default:
        break
    }
    return positions
  }

  //数据构建标绘
  LoadCreate(type, data) {
    var entity = null
    switch (type) {
      case '线':
        entity = this._MeasureLength.loadPolyline(data)
        break
      case '曲线':
        entity = this._DrawCurve.loadCurveline(data)
        break
      case '多边形':
        entity = this._DrawPolygon.loadPolygon(data)
        break
      default:
        break
    }
    return entity
  }

  destroy() {
    this._MeasureLength.destroy()
    this._DrawCurve.destroy()
    this._DrawPolygon.destroy()
  }

  //清空
  clear() {
    this.destroy()
    this._MeasureLength.clear()
    this._DrawCurve.clear()
    this._DrawPolygon.clear()
  }
  //选择清除
  selectrClear() {
    const that = this
    this.destroy()
    this.handler = new this.Cesium.ScreenSpaceEventHandler(this.viewer.viewer.scene.canvas)
    this.handler.setInputAction(function (evt) { //注册单机选择物体删除事件
      const pick = that.viewer.viewer.scene.pick(evt.position)
      if (that.Cesium.defined(pick)) {
        that.viewer.dataSourceDisplay._defaultDataSource.entities.remove(pick.id)
      }
    }, this.Cesium.ScreenSpaceEventType.LEFT_CLICK)
    this.handler.setInputAction(function (evt) { //右击移除当前删除事件
      that.handler.removeInputAction(that.Cesium.ScreenSpaceEventType.LEFT_CLICK)
      that.handler.removeInputAction(that.Cesium.ScreenSpaceEventType.RIGHT_CLICK)
    }, this.Cesium.ScreenSpaceEventType.RIGHT_CLICK)
  }
}


export default plotsUnit
